package com.xj.game;

import java.util.Scanner;

public class Game {
    Customer cs;
    Computer cp;
    int count = 0;// 对战次数
    Scanner sc = new Scanner(System.in);

    public void welcome() {
        System.out.println("**************************");
        System.out.println("**********猜拳游戏开始*********");
        System.out.println("**************************");
    }

    public void menu() {
        int choose = 0;
        do {
            System.out.println("出拳规则：1：剪刀；2：石头；3：布");
            if (cp.name == null) {
                System.out.println("请选择对方的角色（1：刘备；2：孙权；3：曹操）");
                choose = sc.nextInt();
                System.out.println("请输入你的姓名：");
                cs.name = sc.next();
                switch (choose) {
                    case 1:
                        System.out.println(cs.name + "选择刘备对战");
                        cp.name = "刘备";
                        break;
                    case 2:
                        System.out.println(cs.name + "你选择孙权对战");
                        cp.name = "孙权";
                        break;
                    case 3:
                        System.out.println(cs.name + "你选择曹操对战");
                        cp.name = "曹操";
                        break;
                    default:
                        System.out.println(cs.name + "你输错了，请重新选择");
                }
            }
        } while (choose < 1 && choose > 3);

    }

    public void showResult() {

        switch (cs.caiquan) {
            case 1://你出拳剪刀
                switch (cp.caiquan) {
                    case 1:
                        System.out.println("有两下子：你和" + cp.name + "打了平手");
                        break;
                    case 2:
                        System.out.println("真菜，你输给了" + cp.name);
                        cp.score++;
                        break;
                    case 3:
                        System.out.println("真牛：你战胜了" + cp.name);
                        cs.score++;
                        break;
                }
                break;
            case 2://你出拳石头
                switch (cp.caiquan) {
                    case 2:
                        System.out.println("有两下子：你和" + cp.name + "打了平手");
                        break;
                    case 3:
                        System.out.println("真菜，你输给了" + cp.name);
                        cp.score++;
                        break;
                    case 1:
                        System.out.println("真牛：你战胜了" + cp.name);
                        cs.score++;
                        break;
                }
                break;
            case 3://你出拳布
                switch (cp.caiquan) {
                    case 3:
                        System.out.println("有两下子：你和" + cp.name + "打了平手");
                        break;
                    case 1:
                        System.out.println("真菜，你输给了" + cp.name);
                        cp.score++;
                        break;
                    case 2:
                        System.out.println("真牛：你战胜了" + cp.name);
                        cs.score++;
                        break;
                }
                break;
        }
        count++;//比赛次数加1
    }

    public void report() {
        System.out.println(cs.name + "\tVS\t" + cp.name);
        System.out.println("对阵次数：" + count + "; 平手次数：" + (count - cs.score - cp.score));
        System.out.println("姓名\t得分");
        System.out.println(cp.name + "\t" + cp.score);
        System.out.println(cs.name + "\t" + cs.score);
        if (cp.score > cs.score) {
            System.out.println(cp.name + "以" + cp.score + " 比 " + cs.score + " 取得最后的胜利！");
        } else if (cp.score < cs.score) {
            System.out.println(cs.name + "以" + cs.score + " 比 " + cp.score + " 取得最后的胜利！");
        } else {
            System.out.println(cp.name + "以" + cp.score + " 比 " + cs.score + " 战平对手！");
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        Game game = new Game();
        game.cs = new Customer();
        game.cp = new Computer();
        Scanner sc = new Scanner(System.in);
        do {
            game.welcome();
            game.menu();
            game.cs.showFirst();
            game.cp.showFirst();
            game.showResult();
            System.out.println("还要再玩一局么？true/false");
        } while (sc.nextBoolean());
        game.report();

    }
}
